package com.cat.dataStructure;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/make-array-non-decreasing/description/?envType=problem-list-v2&envId=stack
 * @create 2025/9/6 00:11
 * @since JDK17
 */

public class Solution58 {
    public int maximumPossibleSize(int[] nums) {
        int n = nums.length, top = 0;
        int[] stack = new int[n];
        for (int i = 0; i < n; i++) {
            if (top > 0 && stack[top - 1] > nums[i]) {
                stack[top - 1] = nums[i];
            } else {
                stack[top++] = nums[i];
            }
        }
        return top;
    }
}
